package com.sskj.boom.http;


import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.boom.bean.CommonBean;
import com.sskj.boom.bean.HelpBean;
import com.sskj.boom.bean.MyGuessBean;
import com.sskj.boom.bean.OpenAwardBean;
import com.sskj.boom.bean.VcerifyBean;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.base.HttpData;
import com.sskj.common.http.WebSocketObserver;
import com.sskj.lib.Constans;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.bean.SocketSendBean;
import com.sskj.lib.bean.UserData;

import java.util.List;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import io.reactivex.Flowable;
import okhttp3.WebSocket;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {
    /**
     * 开奖校验
     *
     * @param hash
     * @param num
     * @return
     */
    public PostRequest<HttpData<List<VcerifyBean>>> toVcerify(String hash, String num) {
        return OkGo.<HttpData<List<VcerifyBean>>>post(HttpConfig.BASE_URL + HttpConfig.VCERIFY)
                .params("hash", hash)
                .params("num", num);
    }

    /**
     * 开奖历史
     *
     * @param page
     * @param size
     * @return
     */
    public PostRequest<HttpData<PageBean<OpenAwardBean>>> openAwardHistory(int page, int size) {
        return OkGo.<HttpData<PageBean<OpenAwardBean>>>post(HttpConfig.BASE_URL + HttpConfig.OPEN_AWARD)
                .params("page", page)
                .params("size", size);
    }

    /**
     * 我的竞猜
     *
     * @param page
     * @param size
     * @return
     */
    public PostRequest<HttpData<PageBean<MyGuessBean>>> getMyGuessList(int page, int size) {
        return OkGo.<HttpData<PageBean<MyGuessBean>>>post(HttpConfig.BASE_URL + HttpConfig.MY_GUESSES)
                .params("page", page)
                .params("size", size);
    }

    public WebSocketObserver pushBloomType(String type) {
        return new WebSocketObserver(HttpConfig.WS_BASE_URL) {
            @Override
            public void onOpen(WebSocket webSocket, okhttp3.Response response) {
                webSocket.send(new Gson().toJson(new SocketSendBean(type)));
            }
        };
    }

    /**
     * 基础公共数据
     *
     * @return
     */
    public PostRequest<HttpData<CommonBean>> getCommonData() {
        return OkGo.post(HttpConfig.BASE_URL + HttpConfig.COMMON_DATA);
    }

    /**
     * 用户下注
     *
     * @param type
     * @param money
     * @param escape_beishu
     * @return
     */
    public PostRequest<HttpData> normalBet(String type, String money, String escape_beishu) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.NORMAL_BET)
                .params("type", type)
                .params("money", money)
                .params("escape_beishu", escape_beishu);

    }

    /**
     * 用户逃跑
     *
     * @return
     */
    public PostRequest<HttpData> normalRun() {
        return OkGo.post(HttpConfig.BASE_URL + HttpConfig.NORMAL_RUN);
    }

    /**
     * 币种信息
     *
     * @return
     */
    public PostRequest<HttpData> getCoinData() {
        return OkGo.post(HttpConfig.BASE_URL + HttpConfig.COIN_DATA);
    }

    /**
     * 帮助中心
     * @param language
     * @return
     */
    public PostRequest<HttpData<List<HelpBean>>> getFaq(String language) {
        return OkGo.<HttpData<List<HelpBean>>>post(HttpConfig.BASE_URL + HttpConfig.FAQ)
                .params("type", language);
    }

    public GetRequest<HttpData<UserData>> getUserInfo() {
        return OkGo.get(HttpConfig.BASE_URL + HttpConfig.USER_INFO);
    }
}